package com.wws.family.dialog

import android.app.Dialog
import android.content.Context
import android.text.SpannableString
import android.view.Gravity
import android.view.LayoutInflater
import com.wika.basics.base.BaseDialog
import com.wika.framework.manager.AppManager
import com.wws.family.databinding.DialogCommonBinding

/**
 *@Description: 弹出框
 *@Date: 2024/7/26 16:04
 *@Author: WangWeiShuo
 */
class CommonDialog {
    class Builder(
        context: Context
    ) : BaseDialog.Builder<Builder>(context) {
        private val mBinding: DialogCommonBinding = DialogCommonBinding.inflate(LayoutInflater.from(context))

        init {
            setContentView(mBinding.root)
            val width = AppManager.getInstance(context).getScreenWidthPx()
            setWidth((width * 0.8).toInt())
//            setHeight((width * 0.3).toInt())
            setAnimStyle(BaseDialog.AnimStyle.IOS)
            setGravity(Gravity.CENTER)
            mBinding.btnCancel.setOnClickListener {
                dismiss()
            }
        }

        fun showTitle(title: String?): Builder{
            mBinding.tvDialogTitle.text = title
            return this
        }

        fun setTitleColor(titleColor: Int): Builder{
            mBinding.tvDialogTitle.setTextColor(context.getColor(titleColor))
            return this
        }

        fun showContent(content: String?): Builder{
            mBinding.tvDialogContent.text = content
            return this
        }

        fun showContent(content: SpannableString?): Builder{
            mBinding.tvDialogContent.text = content
            return this
        }

        fun showSureText(text: String?): Builder{
            mBinding.btnSure.setText(text)
            return this
        }

        fun setOnSureListener(onSure: (dialog: Dialog?) -> Unit): Builder {
            mBinding.btnSure.setOnClickListener {
                dismiss()
                onSure?.invoke(dialog)
            }
            return this
        }

        fun dismissDialog(){
            dismiss()
        }
    }
}